package client;

/**
 * @(#)Squirrel.java
 *
 *
 * @author Andrew Nelson
 * @version 1.00 2013/2/26
 */
import java.awt.Point;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
//comment
public class Squirrel {
	public enum DIRECTION {NORTH, SOUTH, EAST, WEST};
	public DIRECTION direction = DIRECTION.SOUTH;
	
	public int width = 0;
	public int height = 0;
	public int xVel = 0;
	public int yVel = 0;
	private int leftBound = 0;
	private int rightBound = 0;
	private int topBound = 0;
	private int bottomBound = 0;
	
	Image northImage;
	Image westImage;
	Image eastImage;
	Image southImage;
	
	int score = 0;
	
	Point location = new Point(0, 0);//location is the x and y positions located in the top left of an image for drawing
	
	public boolean isAlive = false;

    public Squirrel(){
    }
    
    public int getHeight(){
    	return height;
    }
    
    public int getWidth(){
    	return width;
    }
    
    public int getXVel(){
    	return xVel;
    }
    
    public int getYVel(){
    	return yVel;
    }
    
    public int getXLoc(){
    	return (int)location.getX();
    }
    
    public int getYLoc(){
    	return (int)location.getY();
    }
    
    public void setXLoc(int x){	
    	location.setLocation(x, location.getY());
    }
    
    public void setYLoc(int y){	
    	location.setLocation(location.getX(), y);
    }
    
    public void keyTyped(KeyEvent e){}
    
    public void keyPressed(KeyEvent e){
		if(e.getKeyCode() == KeyEvent.VK_W || e.getKeyCode() == KeyEvent.VK_UP){
			yVel = -10;
			direction = DIRECTION.NORTH;
		}
		else if(e.getKeyCode() == KeyEvent.VK_A || e.getKeyCode() == KeyEvent.VK_LEFT){
			xVel = -10;
			direction = DIRECTION.WEST;
		}
		else if(e.getKeyCode() == KeyEvent.VK_S || e.getKeyCode() == KeyEvent.VK_DOWN){
			yVel = 10;
			direction = DIRECTION.SOUTH;
		}
		else if(e.getKeyCode() == KeyEvent.VK_D || e.getKeyCode() == KeyEvent.VK_RIGHT){
			xVel = 10;
			direction = DIRECTION.EAST;
		}
	}
	
	public void keyReleased(KeyEvent e){
		if(e.getKeyCode() == KeyEvent.VK_W || e.getKeyCode() == KeyEvent.VK_S || e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_DOWN){
			yVel = 0;
		}
		
		if(e.getKeyCode() == KeyEvent.VK_A || e.getKeyCode() == KeyEvent.VK_D || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT){
			xVel = 0;
		}
	}
	
	//add stuff for bounds	
	public void update(){
		location.setLocation(getXLoc() + xVel, getYLoc() + yVel);
		
		if(location.getX() - width/2 < leftBound){
			setXLoc(width/2 + leftBound);
		}
		if(location.getY() - height/2 < topBound){
			setYLoc(height/2 + topBound);
		}
		if(location.getX() + width/2 > rightBound){
			setXLoc(rightBound - width/2);
		}
		if(location.getY() + height/2 > bottomBound){
			setYLoc(bottomBound - height/2);
		}
	}
	
	public void setBounds(int l, int r, int t, int b){
		leftBound = l;
		rightBound = r;
		topBound = t;
		bottomBound = b;
	}
}